package com.decent.ejfadmin.user.dao.provider;

import com.decent.ejfadmin.user.bean.BankCodeMap;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Objects;

/**
 * describe:
 *
 * @author JunLei He
 * @date 2018年11月08日
 */
public class UserWithdrawBankProvider {
    /**
     * 查询会员提现列表
     *
     * @param map 参数集合
     * @return 返回sql
     */
    public String queryUserWithdrawBankList(HashMap<String, Object> map) {
        StringBuilder sql = new StringBuilder(50);
        sql.append(" SELECT " +
                " b.id, " +
                " u.account, " +
                " b.bank_name bankName, " +
                " b.bank_no bankNo, " +
                " b.bank_account_type bankAccountType, " +
                " b.bank_code bankCode, " +
                " b.bank_salt bankSalt, " +
                " b.bank_telephone bankTelephone, " +
                " b.gmt_create gmtCreate, " +
                " b.gmt_modified gmtModified, " +
                " b.is_use isuse, " +
                " b.`name` " +
                "FROM " +
                " yuhuang_withdraw_bank b, " +
                " yuhuang_sup_user u " +
                "WHERE " +
                " u.user_id = b.user_id ");
        String account = (String) map.get("account");
        if (StringUtils.isNotBlank(account)) {
            sql.append(" and account = #{account} ");
        }
        Integer state = (Integer) map.get("state");
        if (Objects.nonNull(state)) {
            sql.append("  and b.is_use =#{state} ");
        }
        sql.append(" ORDER BY u.account,b.gmt_create ");
        return sql.toString();
    }

    /**
     * 查询银行编码映射
     *
     * @param map
     * @return
     */
    public String queryBankCodeMap(HashMap<String, BankCodeMap> map) {
        StringBuilder sql = new StringBuilder(50);
        sql.append(" SELECT\n" +
                "id,\n" +
                "bankName,\n" +
                "bankAccountType,\n" +
                "bankCode,\n" +
                "payBank\n" +
                "FROM\n" +
                "yuhuang_bank_code_map " +
                "WHERE " +
                " 1=1 ");
        BankCodeMap bankCodeMap = map.get("bankCodeMap");
        if (StringUtils.isNotBlank(bankCodeMap.getPayBank())) {
            sql.append(" and instr(payBank, #{bankCodeMap.payBank} )>0 ");
        }
        if (StringUtils.isNotBlank(bankCodeMap.getBankName())) {
            sql.append(" and instr(bankName, #{bankCodeMap.bankName} )>0 ");
        }
        if (StringUtils.isNotBlank(bankCodeMap.getBankAccountType())) {
            sql.append(" and instr(bankAccountType, #{bankCodeMap.bankAccountType} )>0  ");
        }

        sql.append(" ORDER BY id  desc ");
        return sql.toString();
    }
}
